<?php
/**
 * 用户中心控制器congcong
 */
namespace Home\Controller;
use Think\Controller;
class UserController extends HomeController{
    /**
     * 个人中心控制器
     */
    public function index()
    {
         $where['uid']=!empty($_SESSION['uid'])?$_SESSION['uid']:'';
         
         $result=M('user')->where($where)->find();///手机端登陆获取用户名

        
         $this->assign('result',$result);
      
         $this->display();
    }

   /*
     *获取用户推广收入
     *@uid 
     *return josn
     */
    public function getIncome(){
        $result='';
        $page=I('post.page',1,'strip_tags');
        $uid=!empty($_SESSION['uid'])?intval($_SESSION['uid']):0;
        if(empty($uid))
        {
            $result['status']=0;
            $result['msg']='系统繁忙，请稍后再试';
            echo json_encode($result);
            return '';

        }

        $count=M()->query("select count(*) as count from ".C('DB_PREFIX').'allocation_record where uid='.$uid);
        $pagearr= getPageArr($page,C('PAGESIZE'),$count[0]['count']);
        
        //获取当前用户的分成记录
        $logs=M('allocation_record a ')->join('inner join '.C('DB_PREFIX').'user b on a.sourceid=b.uid')
                                 ->where('a.uid=%d',$uid)
                                 ->limit($pagearr['start'],$pagearr['pagesize'])
                                 ->getField('a.id,a.order_sn,a.money,b.nickname,FROM_UNIXTIME(a.addtime, "%Y-%m-%d") as addtime');
       
        
        if(empty($logs))
        {
            $result['status']=0;
            $result['msg']='暂无记录';
            echo json_encode($result);
            return '';
        }
        $result['logs']=array_values($logs);
        $result['status']=1;
        $result['pagearr']=$pagearr;
        echo json_encode($result);


    }
    

}